package com.jilian.powerstation.modul.natives;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jilian.powerstation.Constant;
import com.jilian.powerstation.MyApplication;
import com.jilian.powerstation.R;
import com.jilian.powerstation.base.BaseFragment;
import com.jilian.powerstation.modul.activity.LoginActivity;
import com.jilian.powerstation.utils.PinziDialogUtils;
import com.jilian.powerstation.utils.RxTimerUtil;
import com.jilian.powerstation.utils.SPUtil;
import com.jilian.powerstation.utils.ToastUitl;

public class TwoNativeFragment extends BaseFragment {
    private TextView tvOne;
    private TextView tvTwo;
    private TextView tvThree;


    @Override
    protected void loadData() {

    }

    @Override
    protected void createViewModel() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_twonative;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        setNormalTitle("Real-time flow graph", v -> getActivity().finish());
        tvOne = (TextView) view.findViewById(R.id.tv_one);
        tvTwo = (TextView) view.findViewById(R.id.tv_two);
        tvThree = (TextView) view.findViewById(R.id.tv_three);
    }

    @Override
    protected void initData() {
        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getmActivity(), BaseSettingActivity.class));
            }
        });
        tvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                showPWDtDialog();
            }
        });

        tvThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getmActivity(), WindowActivity.class));


            }
        });


    }

    private void showPWDtDialog() {
        Dialog dialog = PinziDialogUtils.getDialogNotTouchOutside(getmActivity(), R.layout.dialog_input_pwd);


        EditText etPwd = (EditText) dialog.findViewById(R.id.et_pwd);

        TextView tvNo = (TextView) dialog.findViewById(R.id.tv_no);
        TextView tvOk = (TextView) dialog.findViewById(R.id.tv_ok);

        tvOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(etPwd.getText().toString())) {
                    return;
                }
                if ("admin".equals(etPwd.getText().toString())) {
                    startActivity(new Intent(getmActivity(), AdvancedSettingActivity.class));
                    dialog.dismiss();
                } else {
                    ToastUitl.showImageToastTips("error password");
                }
            }
        });
        tvNo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();


    }

    @Override
    protected void initListener() {

    }
}
